#!/bin/sh
# Begin /etc/init.d/template

### BEGIN INIT INFO
# Provides:            template
# Required-Start:
# Should-Start:
# Required-Stop:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description:
# Description: 
# X-LFS-Default-Start:
# X-LFS-Default-Stop:
# X-LFS-Provided-By:
### END INIT INFO

# Source the LSB init-functions, ours are pulled in from there.
. /lib/lsb/init-functions

# These are optional, but required for chk_stat.  They will be used in 
# the rest of the functions if defined, else you must provide a program
# name to control, and a message ('Starting Template Service...' 
# or 'Stoping Template Service...') to evauate_retval.  See the 
# documentaion in the lfs-fucntions file for more information.
MESSAGE="Template Service"
BIN_FILE="/some/path/to/template"
CONFIGFILE="/etc/sysconfig/template.conf"

# check that $BIN_FILE exists and is executable, and $CONFIGFILE exists.
chk_stat

# LSB Defined functions require that at least $BIN_FILE be passed to them,
# where as lfs-functions will use the $BIN_FILE environment variable.
# loadproc() and endproc() are just wrappers that pass everything on to 
# the LSB defined functions.

case "${1}" in
    start)
        #start_daemon "${BIN_FILE}" -arg1 -arg2 #... or:
        loadproc -arg1 -arg2 -arg3 #...
        evaluate_retval start
        ;;

    stop)
        #killproc -TERM "${BIN_FILE}" or:
        endproc
        evaluate_retval stop
        ;;

    force-reload)
        reloadproc -force
        evaluate_retval force-reload
        ;;

    restart)
        $0 stop
        $0 start
        ;;

    status)
        statusproc
        ;;

# reload and try-restart are optional per LSB requirements
    reload)
        reloadproc
        evaluate_retval reload
        ;;

    try-restart)
	# Since this is optional there is no lfs-function for this one...
        # might be at a later time if used enough, but I doubt it usefullness.
        pidofproc "${BIN_FILE}" > /dev/null
        if [ "${?}" -ne "0" ]; then
            MESSAGE="${MESSAGE}: Not Running"
        else
            $0 stop
            $0 start
            exit 0
        fi
        evaluate_retval try-restart
        ;;

    *)
        echo "Usage: ${0} {start|stop|{force-}reload|{try-}restart|status}"
        exit 1
        ;;
esac

# End /etc/init.d/template
